package com.jianyushe.common.util;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author Create by Alvin
 * @Description TODO
 * @date 2022-04-19 20:28
 */
public class PoiReadExcelDemo {

    @Test
    public void readExcelBySXXF() throws IOException {
        // 获取输入文件流 使用try with resource这种方式替代finally关闭文件方式
        try (FileInputStream fileInputStream = new FileInputStream("F:\\Temp\\" + "test07版本.xlsx")) {
            // 创建工作薄对象
            Workbook workbook = new XSSFWorkbook(fileInputStream);
            Sheet sheet = workbook.getSheet("Sheet0");
            Row row = sheet.getRow(1);
            Cell cell = row.getCell(1);
            JianYusheBaseConsoleUtil.printMessage(cell.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
